﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using POSSystem.DAL;

namespace POSSystem.BLL
{
    public class RepairJobProblems : _RepairJobProblems
    {
        public static RepairJobProblems GetProblemsByRepairID(int jobID)
        {
            RepairJobProblems p = new RepairJobProblems();
            p.Where.RepairJobID.Value = jobID;
            p.Query.Load();

            return p;
        }

        public static void SetRejectedPrice(int jobID)
        {
            RepairJobProblems p = new RepairJobProblems();
            p.Where.RepairJobID.Value = jobID;
            p.Query.Load();

            for (int i = 0; i < p.RowCount; i++)
            {
                p.PreviousPrice = p.Price;
                p.Price = 0;
                
                p.MoveNext();
            }

            p.Save();
        }

        public static void SavePrice(int jobID)
        {
            RepairJobProblems p = new RepairJobProblems();
            p.Where.RepairJobID.Value = jobID;
            p.Query.Load();

            for (int i = 0; i < p.RowCount; i++)
            {
                if (!p.IsColumnNull(RepairJobProblems.ColumnNames.Price))
                    p.PreviousPrice = p.Price;

                p.MoveNext();
            }

            p.Save();
        }

        public static void RestorePrice(int jobID)
        {
            RepairJobProblems p = new RepairJobProblems();
            p.Where.RepairJobID.Value = jobID;
            p.Query.Load();

            for (int i = 0; i < p.RowCount; i++)
            {
                if (!p.IsColumnNull(RepairJobProblems.ColumnNames.PreviousPrice))
                    p.Price = p.PreviousPrice;

                p.MoveNext();
            }

            p.Save();
        }
    }
}
